package org.schhx;

import org.schhx.io.Resources;
import org.schhx.mapper.UserMapper;
import org.schhx.pojo.User;
import org.schhx.session.SqlSession;
import org.schhx.session.SqlSessionFactory;
import org.schhx.session.SqlSessionFactoryBuilder;

import java.io.InputStream;
import java.util.List;

/**
 * @author shanchao
 * @date 2021/1/30
 */
public class IPersistenceMapperTest {

    public static void main(String[] args) throws Exception {
        InputStream inputStream = Resources.getResourceAsStream("sqlSessionMap.xml");
        SqlSessionFactory sqlSessionFactory = SqlSessionFactoryBuilder.build(inputStream);
        SqlSession session = sqlSessionFactory.open();

        UserMapper userMapper = session.getMapper(UserMapper.class);

        List<User> users = userMapper.findAll();
        for (User user : users) {
            System.out.println(user);
        }

        User condition = new User();
        condition.setId(1);
        condition.setUsername("lucy");
        User user = userMapper.findByCondition(condition);
        System.out.println(user);
    }
}
